﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;

namespace tactics
{
    using UnitList = List<Unit>;

    public class Player
    {
        UnitList    units;
        string      name;
        int         number;
        Color       colour;
        int         points;

        int         initiative;
        
        #region Properties

        public UnitList Units
        {
            get
            {
                return units;
            }
            set
            {
                units = value;
            }
        }

        public string Name
        {
            get
            {
                return name;
            }
        }

        public int Number
        {
            get
            {
                return number;
            }
        }

        public Color Colour
        {
            get
            {
                return colour;
            }
        }

        public int Points
        {
            get
            {
                return points;
            }
            set
            {
                points = value;
            }
        }

        public int Initiative
        {
            get
            {
                return initiative;
            }
            set
            {
                initiative = value;
            }
        }

        #endregion

        public Player(int numberIn, string nameIn)
        {
            number = numberIn;
            name = nameIn;
            units = new UnitList();
            points = 75;

            SetColour();
        }

        #region Accessors

        public Unit GetUnit(int idx)
        {
            return units[idx];
        }

        #endregion

        private void SetColour()
        {
            // this should come from an xml file at some point
            if (number == 0)
            {
                //colour = Color.RoyalBlue;
                colour = new Color(0f, 0f, 0.75f, 1f);
            }
            else if (number == 1)
            {
                colour = new Color(0.75f, 0.0f, 0.0f, 1f);
            }
            else
            {
                colour = Color.Black;
            }            
        }

        public int AddUnit(Unit unit)
        {
            if (points - unit.PointCost >= 0)
            {
                points -= unit.PointCost;
                units.Add(unit);
            }

            return units.Count;
        }
    }
}
